package com.csthink.auditlog.util;

import com.csthink.auditlog.domain.AuditLogOperator;
import com.csthink.mysql.entity.User;

import java.util.Objects;

/**
 * @author <a href="mailto:security.2009@live.cn">Mars</a>
 * @since 2023-09-12
 */
public class AuditLogAuthUtil {

    public static AuditLogOperator getOperator() {
        // todo spring security

        return new AuditLogOperator();

//        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
//        AuditLogOperator operator = new AuditLogOperator();
//        if (authentication == null || authentication.getPrincipal() == null) {
//            return operator;
//        }
//        if (authentication.getPrincipal() instanceof OpUserDTO){//op: OpUserDTO can not be got from AuthenticationInfoUtil
//            OpUserDTO user = (OpUserDTO) authentication.getPrincipal();
//            operator.setId(user.getId());
//            operator.setEmail(user.getEmail());
//            return operator;
//        }
//        User user = AuthenticationInfoUtil.getLoginUser();//web
//        if (Objects.nonNull(user)){
//            operator.setId(user.getId());
//            operator.setAccountId(user.getAccountId());
//            operator.setEmail(user.getEmail());
//        }
//        return operator;
    }

    public static String getAccountId(){
        return getOperator().getAccountId();
    }
}
